import router from '@/router/index'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import { useUserStore } from '@/stores/modules/user'
const userstore=useUserStore()
const whiteList=['/login','/404']
router.beforeEach((to , from ,next)=>{
nprogress.start()
console.log('dsa',userstore.token)
if(userstore.token){
//存在token
if(to.path==='/login'){
    nprogress.done()
    next('/')
}
else {
    console.log('存在tkoen')
    next()
}
}
else {
//没有token
if (whiteList.includes(to.path)){
next()
}
else {
next('/login')
}
}

})

router.afterEach((to,from,next)=>{
nprogress.done()
})